iT邦幫忙

2023 iThome 鐵人賽

DAY 30
0
DevOps

SRE/K8S 碎碎念系列 第 30

D30

  • 分享至 

  • xImage
  •  

雖然前面有提到雖然 K8S 內建有 load balance 機制,但是建立在 L4 上。所以只有不具備真正持久連線的 HTTP 可以使用。但真正具有持久連線的 gRPC,L4 就無法進行幫忙,導致擴展 pod 之後無法將流量導過去新的 pod 上,所以我們引用 app mesh 功能。

但 AWS 有提出不需要這麼麻煩建立 app mesh 的 解法,就是直接使用 AWS ALB ,在 2020/10 ,ALB 支援了 HTTP/2 and gRPC load balancing,這邊我們就來了解內容。

準備好 gRPC application 的 ECR image

  1. git clone https://github.com/grpc/grpc/tree/master/examples/python/route_guide

  2. 建立 Docker file

    FROM python:3.7
    RUN pip install protobuf grpcio
    COPY ./grpc/examples/python/route_guide .
    CMD python route_guide_server.py
    EXPOSE 50051
    
  3. 上傳到 ECR

    aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 123412341234.dkr.ecr.eu-north-1.amazonaws.com
    docker build -t route-guide .
    docker tag route-guide:latest 123412341234.dkr.ecr.eu-north-1.amazonaws.com/route-guide:latest
    docker push 123412341234.dkr.ecr.eu-north-1.amazonaws.com/route-guide:latest
    

建立 cluster 跟 network 環境

  1. 建立 EKS cluster

  2. 建立 security group,並允許自己的電腦IP位置可以 TCP 連線到此 SG

  3. 建立 TG

    apiVersion: v1
    kind: Service
    metadata:
      name: route-guide
    spec:
      ports:
        - port: 50051
          targetPort: 50051
          protocol: TCP
          name: grpc
      selector:
        app: route-guide
    
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: route-guide-ingress
      annotations:
        kubernetes.io/ingress.class: alb
        alb.ingress.kubernetes.io/scheme: internet-facing
        alb.ingress.kubernetes.io/target-type: ip
        alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
        alb.ingress.kubernetes.io/backend-protocol-version: HTTP
        alb.ingress.kubernetes.io/group.name: route-guide
    spec:
      rules:
      - http:
          paths:
          - path: /*
            pathType: ImplementationSpecific
            backend:
              service:
                name: route-guide
                port:
                  number: 50051
    

EKS 上部署 pod

  1. sevice file

    apiVersion: v1
    kind: Service
    metadata:
      name: eks-service
    spec:
      selector:
        app: your-app-name
      ports:
        - protocol: TCP
          port: 50051
          targetPort: 50051
      type: LoadBalancer
    

部署 ingress (ALB)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: route-guide-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
  - http:
      paths:
      - path: /*
        pathType: ImplementationSpecific
        backend:
          service:
            name: route-guide
            port:
              number: 50051

ref: https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-a-grpc-based-application-on-an-amazon-eks-cluster-and-access-it-with-an-application-load-balancer.htmlrre

ref: https://aws.amazon.com/tw/blogs/aws/new-application-load-balancer-support-for-end-to-end-http-2-and-grpc/


上一篇
D29
系列文
SRE/K8S 碎碎念30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言